package study.ct.com.retrofit_rxjava.activity;

import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;

import study.ct.com.retrofit_rxjava.receiver.MyReceiver;

/**
 * Created by ct on 2017/10/12 0012.
 */

public class BroadcastActivity extends Activity {



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    MyReceiver receiver;
    /*
    * 动态注册 receiver
    * */
    @Override
    protected void onResume() {
        super.onResume();

         receiver=new MyReceiver();
        IntentFilter intentFilter = new IntentFilter();

        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        //调用Context的registerReceiver（）方法进行动态注册
        registerReceiver(receiver, intentFilter);
    }

    /*
    * 动态注销 receiver
    * 动态注册的广播 必须要注销，不然会导致内存泄漏
    * activity 被kill的时候不会执行 onStop  onDestroy  所以在onPause中注销
    * */
    @Override
    protected void onPause() {
        super.onPause();
    }
}
